Socket
Socket
Sign inDemoInstall

typanion

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

typanion

Simple runtime TypeScript validator library


Version published
Maintainers
1
Created

What is typanion?

The typanion npm package is a comprehensive solution for runtime input validation in JavaScript and TypeScript applications. It allows developers to ensure that the data their applications process meets certain criteria, thereby preventing unexpected errors and improving data integrity. Typanion offers a flexible and expressive API for defining validation rules, making it suitable for a wide range of use cases.

What are typanion's main functionalities?

Basic Type Validation

This feature allows for basic type validation, such as checking if a value is a number. The code sample demonstrates how to use the `isNumber` function to validate numeric values.

{"const {isNumber} = require('typanion');
const validate = isNumber();
console.log(validate(42)); // {ok: true, errors: []}
console.log(validate('hello')); // {ok: false, errors: [...]}"}

Complex Object Validation

This feature enables complex object validation, allowing developers to validate nested objects and apply multiple validation rules. The code sample shows how to validate a user object with both `name` and `email` fields.

{"const {isObject, isString, applyCascade} = require('typanion');
const validateUser = isObject({
  name: isString(),
  email: applyCascade(isString(), [isEmail()])
});
console.log(validateUser({name: 'John Doe', email: 'john@example.com'})); // {ok: true, errors: []}"}

Custom Validation Rules

Typanion allows for the creation of custom validation rules. This feature is particularly useful for domain-specific validations. The code sample illustrates how to define and use a custom validator to check if a person is an adult.

{"const {createValidator} = require('typanion');
const isAdult = createValidator({
  test: (value) => value >= 18,
  message: (value) => `${value} is not an adult`
});
console.log(isAdult(21)); // {ok: true, errors: []}
console.log(isAdult(16)); // {ok: false, errors: [...]}"}

Other packages similar to typanion

FAQs

Package last updated on 06 Aug 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc